<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="copyright" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<title>优惠券</title>
<link href="<%=path%>/favicon.ico" rel="shortcut icon">
<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/dataTables/css/jquery.dataTables.min.css">
<link href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css"
	rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/datapicker/bootstrap-datetimepicker.min.css">
</head>
<style>
table.dataTable tbody th, table.dataTable tbody td {
    padding: 0px 10px;
}
</style>
<body>
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-12 text-right">
			   <i class="fa fa-times" onclick="javascript:colseCouponModal()"></i>
			</div>
			
			<div class="tabs-container">
			    <ul class="nav nav-tabs">
					<li id="sysCoupon" class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">优惠券</a>
					</li>
				</ul>
			
			    <div class="tab-content">
					<div id="tab-1" class="tab-pane active">
						<div class="panel-body" style="padding-bottom: 0px;">
							<div class="col-md-12" style="margin-top:15px">
						       <form action="" class="form-inline col-sm-6">
								    <div class="form-group">
								       <label>关键字</label>
								       <input class="form-control" id="keyWord" type="text" placeholder="输入电子券名称" maxlength="20" onblur="checkLength(this)">
								    </div>
								    <div class="form-group" style="margin-left: 15px;">
								        <button id="coupon_search"   type="button" class="btn btn-primary">搜索
					                    </button>
								    </div>
							   </form>
						    </div>
						    <div class="col-sm-12" style="margin-top:20px;padding-bottom: 0px;">
				                         <table class="table-striped table-bordered table-hover" id="mydataTable" style="width:100%;">
				                            <thead>
				                                <tr>
				                                    <th>序号</th>
				                                    <th>选择</th>
				                                    <th>名称</th>
				                                    <th>金额</th>
				                                    <th>使用条件</th>
				                                    <th>有效期</th>
				                                </tr>
				                            </thead>
				                            <tbody>
				                               
				                            </tbody>
				                        </table>
				                    </div>                 
						</div>
					</div>
					
		    <div class="col-md-12 text-center" style="width:100%;margin-top: 15px">
		        <div class="col-md-3"></div>
		        <button type="button" onclick="javascript:colseCouponModal();" class="col-md-2 btn btn-w-m btn-outline btn-primary">取消</button> 
		        <div class="col-md-2"></div>
			    <button type="button" onclick="javascript:determineCoupon();" class="col-md-2 btn btn-w-m btn-primary">确定</button> 
			    <div class="col-md-3"></div>
		    </div>
	    </div>			
	</div>
</div>
  	</div>
</div>  
    <div class="modal inmodal fade" id="couponStatistics" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
               
            </div>
        </div>
    </div>
    
    
    

	<script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
	<script
		src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
	<script
		src="<%=path%>/hplus/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/clockpicker/clockpicker.js"></script>
	<script src="<%=path%>/hplus/js/plugins/cropper/cropper.min.js"></script>
	<script type="text/javascript"
		src="<%=path%>/hplus/js/plugins/dataTables/jquery.dataTables.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
    <script type="text/javascript" src="<%=path%>/js/dateUtils.js"></script>

<script type="text/javascript">

</script>

<script type="text/javascript">
$(function(){
	    var path = "<%=path%>";
	    var myDataTable;
	   	var keyWord="";
	   	/* var startTime="";
	   	var endTime=""; */
	    var name="";
	    var face_value="";
	    var ids="";
	    /* var startTime;
	    var endTime; */
	    $.fn.dataTable.ext.errMode = 'none';
	    $(function(){
	    	init();
	    	
	    });
	    
	    function init(){
	    	/* var myDate = new Date();
	    	//获取当前年
	    	var year=myDate.getFullYear();
	    	//获取当前月
	    	var month=myDate.getMonth()+1;
	    	var beforeMonth=myDate.getMonth();
	    	var beforeYear=year;
	    	//获取当前日
	    	var day=myDate.getDate(); 
	    	if(month>12){
	    		year=year+1;
	    		month=1;
	    	}
	    	if(beforeMonth==0){
	    		beforeMonth=12;
	    		beforeYear=beforeYear-1;
	    	}
	    	console.log(year+"-"+month+"-"+day);
	    	console.log(beforeYear+"-"+beforeMonth+"-"+day);
	    	
	    	console.log($("#starttime"));
	    	//document.getElementById("endtime").value = year+"-"+month+"-"+day; 
	    	$("#endtime").val(year+"-"+month+"-"+day);
	    	$("#endtime").attr("value",year+"-"+month+"-"+day);
	    	$("#starttime").attr("value",beforeYear+"-"+beforeMonth+"-"+day);
	    	$("#starttime").val(beforeYear+"-"+beforeMonth+"-"+day); 
	    	
	    	$("#starttime").datepicker("setDate",beforeYear+"-"+beforeMonth+"-"+day);
	    	$("#endtime").datepicker("setDate",year+"-"+month+"-"+day);  */
	    	
	    	
	    	myDataTable = dataTable();
	    };
	    var lineNum = 0;
	    function dataTable(){
	    	return $('#mydataTable').DataTable({
	    		processing: true,
	    		ordering: false,
	    		searching: false,
	    		info: true,
	    		autoWidth: true,
	    		lengthChange: false,
	    		"order": [[ 2, "desc" ]],
	    	    language: {
	    	    	emptyTable: '无数据',
	    	    	info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
	    			infoEmpty: '没有数据',
	    			lengthMenu: '每页显示 _MENU_ 条记录',
	    			loadingRecords: '正在加载数据....',
	    			processing: '正在处理数据....',
	    			zeroRecords: '没有找到匹配的记录',
	    			paginate: {
	    				first: '首页',
	    				previous: '前页',
	    				next: '后页',
	    				last: '尾页'
	    			}
	    	    },
	    	    order: [[1,'desc']],
	    		pageLength: 5,
	    	    pagingType: 'full_numbers',
	    	    columnDefs: [{
	    			render: function(data, type, full) {
	    				var oTable = $('#mydataTable').dataTable();
        				var tableSetings=oTable.fnSettings();  
        				var paging_length=tableSetings._iDisplayLength;//当前每页显示多少  
        				var page_start=tableSetings._iDisplayStart;//当前页开始  
        				var page=(page_start / paging_length);
        				lineNum++;
        				return (page*5+lineNum);
	                },
	    			targets: 0
	    		},{
	    			render: function(data, type, full) {
	    				var result="";
	    				if(IsCheck(data)){
	    					result='<div class="checkbox i-checks"><label class="is_checkd select_one" couponId="'+data+'" couponName="'+full.name+'" id="'+data+'"><input checked="checked" class="childCheckbox" type="checkbox" couponName="'+full.name+'" id="'+data+'"></label></div>';

	    				}else{
	    					 result='<div class="checkbox i-checks"><label class="is_checkd select_one" couponId="'+data+'" couponName="'+full.name+'" id="'+data+'"><input  class="childCheckbox" type="checkbox" couponName="'+full.name+'" id="'+data+'"></label></div>';

	    				}
	                    return result;
	                },
	    			targets: 1
	    		},{
	    			render: function(data, type, full) {
	    				if(StringEmpty(data)){
	    					return (Number(data)/100)+"元";
	    				}else{
	    					return "";
	    				}
	                },
	    			targets: 3
	    		},{
	    			render: function(data, type, full) {
	    				var result="";
	    				if(StringEmpty(data)&&data!="0"){
	    					result="满"+Number(data)/100+"元使用";
	    				}else{
	    					result="无";
	    				}
	    				return result;
	                },
	    			targets: 4
	    		},{
	    			render: function(data, type, full) {
	    				
	    				var result="";
	    				var validityPeriodType=full.validityPeriodType;
	    				if(validityPeriodType==0){
	    					if(StringEmpty(full.startTime) && StringEmpty(full.endTime)){
	    						result=formatDateTimeYMD(full.startTime)+"—"+formatDateTimeYMD(full.endTime);
	    					}
	    				}else if(StringEmpty(full.afterDay)&&validityPeriodType==1){
	    					result="优惠券发送后"+full.afterDay+"天有效";
	    				}
	    				
	    				
	    				return result;
	                },
	    			targets: 5
	    		}],
	    	    columns: func_columns(),
	    	    serverSide: true,
	    	   
	    	    ajax: {
	    	    	contentType: 'application/json;charset=utf-8',
	    	    	type: 'POST',
	    	    	url: func_AjaxUrl(),
	    	    	data: function(d){
	    	    		d.keyWord=keyWord;
	    	    		d.status=1;
	    	    		if(validityType == 1){
	    	    			d.validityStartTime = startTime;
	    	    			d.validityEndTime = endTime;
	    	    		}
	    				return JSON.stringify(d);
	    			}
	    		}
	    	    ,
	    	    "initComplete": function(settings, json) {
	    	    	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
	    	      }
	    	}).on( 'draw', function () {
	    		$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

	    	}).on( 'page.dt', function () {
        		    lineNum = 0;
        	});
	    	
	    };
	    
	    
	    
	    
	    
	    function func_AjaxUrl(){
	    	return path+"/couponDefinedTemplate/ajaxCouponDefinedTemplatePageList";
	    };
	    /**
	     *	设置列名，对应后台
	     */
	    function func_columns(){
	    	var jsonArr = [
	    		{"data":"id"},
	    		{"data":"id"},
	    		{"data":"name"},
	    		{"data":"faceValue"},
	    		{"data":"limitPrice"},
	    		{"data":"endTime"},
	    	];
	    	return jsonArr;
	    };
	    
	    $('#coupon_search').on("click",function(){
	    	keyWord=$('#keyWord').val();
	    	/* startTime=$('#starttime').val();
	    	endTime=$('#endtime').val(); */
	        func_dataTableReload();
	    });
	    function func_dataTableReload(){
	    	myDataTable.ajax.reload(function(){
	    		/* $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green"});
	    		$('input').iCheck('uncheck'); */
	    	});
	    };
	    
	    
		     
	     //判断是否被选中
	     function IsCheck(id){
	    	 var result=false;
    		 for(var i in couponIdArray){
	    		 if(couponIdArray[i]==id){
	    			 result=true;
	    			 break; 
	    		 }
	    	 }
	    	 return result;
	     };
});




</script>


</body>
</html>